var codeFlag = 0;//用于判断验证码是否发送
var codeCount = 60;
var timeBean = null;


function submit() {
    $.ajax({
        type: "post",
        url: common.userRegisterUrl,
        data: $('#myForm').serialize(),
        success: function (result) {
            //这里是解析的json数据   直接返回data
            var resultDate = result;
            var data = resultDate.data;
            console.log(resultDate);
            var list = data.states;
            if (resultDate.code == 0) {
                common.showMsgTips("注册成功");
                window.location = 'success.html?type=reg';
            } else {
                common.showMsgTips(resultDate.msg);
            }
        }
    });
}

function sendCode(bean) {
    var emailAvailable = common.isEmailAvailable($('#mailBox').val());
    if (emailAvailable) {//正常邮箱
        if (codeFlag == 0) {
            codeFlag = 1;
            timeBean = window.setInterval(function () {
                codeCount--;
                $('#sendCode').text("已发送 " + codeCount+"s");
                if (codeCount <= 0) {
                    window.clearInterval(timeBean); //停止计时器
                    $('#sendCode').css("color", "#22a3f9");
                    $('#sendCode').css("border", " 1px solid #22a3f9");
                    $('#sendCode').text("发送验证码");
                    codeFlag = 0;
                    codeCount=60;
                }
            }, 1000); //启动计时器，1秒执行一次
            $.ajax({
                type: "get",
                url: common.getVerificationCodeUrl,
                data: $('#myForm').serialize(),
                success: function (result) {
                    //这里是解析的json数据   直接返回data
                    var resultDate = result;
                    console.log(resultDate);
                }
            });

            $('#sendCode').css("color", "#cccccc");
            $('#sendCode').css("border", " 1px solid #cccccc");
        }
    } else {
        common.errorTips("请输入正确邮箱");
    }


}


